package com.baboba.rummy.card.validator;

import java.util.List;

import com.baboba.rummy.card.Card;

public class VerticalValidator<T extends Card> implements IValidator<T> {

	@Override
	public boolean validate(List<T> cards) {
		if (cards.size()<3 || cards.size()>4)
			return false;
		
		boolean[] colorMap = new boolean[4];
		int lastNumber=0;
		for (int i=0;i<cards.size();i++){
			if (cards.get(i).getNumber() == 0)
				continue;
			
			if (lastNumber!=0 && lastNumber!=cards.get(i).getNumber())
				return false;
			
			if (colorMap[cards.get(i).getColor().ordinal()] == true)
				return false;
			
			colorMap[cards.get(i).getColor().ordinal()] = true;
			lastNumber = cards.get(i).getNumber();
		}
		
		return true;
	}

}
